package com.feicheng.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.feicheng.base.common.DaoConstant;
import com.feicheng.base.result.Result;
import com.feicheng.entity.User;
import com.feicheng.entity.Warehouse;
import com.feicheng.entity.WarehouseStore;
import com.feicheng.service.IStoreService;
import com.feicheng.service.IUserService;
import com.feicheng.service.IWarehouseService;
import com.feicheng.service.IWarehouseStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hao.zhang
 * @since 2022-07-04
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    IUserService iUserService;

    @Autowired
    IWarehouseStoreService iWarehouseStoreService;

    @Autowired
    IWarehouseService iWarehouseService;

    /**
     * 管理员下拉查询
     * @autor hao.zhang
     * @param
     * @return
     */
    @PostMapping("/info/all/g")
    public Result getUserList(Integer storeId) {

        //查询门店下所有员工
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq(DaoConstant.STORE_USER.STORE_ID, storeId);

        //返回结果集
        return Result.success(iUserService.list(userQueryWrapper));

//        //查询门店下所有仓库id
//        QueryWrapper<WarehouseStore> warehouseStoreQueryWrapper = new QueryWrapper<>();
//        warehouseStoreQueryWrapper.eq(DaoConstant.WAREHOUSESTORE.STORE_ID, storeId);
//        List<WarehouseStore> warehouseStores =  iWarehouseStoreService.list(warehouseStoreQueryWrapper);
//
//        //遍历取出仓库管理员信息
//        List<User> users = new ArrayList<>();
//        Iterator<WarehouseStore> iterator = warehouseStores.iterator();
//        while (iterator.hasNext()){
//           users.add(iUserService.getById(iWarehouseService.getById(iterator.next().getWarehouseId()).getUserId()));
//        }
    }
}

